package com.youjia.center.boot.data.mp.helper;

import com.alibaba.fastjson.JSONObject;
import com.youjia.center.boot.data.mp.basic.dto.PagedListDto;
import org.springframework.util.Assert;

/**
 * 分页帮助类
 * @author fengjiansong
 * @date 2022/5/22 10:18
 */
public class PageListHelper {

    /**
     * 将分页内容做map转换
     * @param source 转换前
     * @param target 转换后
     * @return target 分页结构数据
     */
    public static <T> PagedListDto<T> pageListMap2Class(PagedListDto<?> source, Class<T> target) {

        Assert.notNull(source,"source不能为空");

        var sourceList = source.getList();

        var mapList = JSONObject.parseArray(JSONObject.toJSONString(sourceList),target);

        return new PagedListDto(source.getTotal(),source.getPageSize(),source.getPageIndex(),mapList);
    }
}
